home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
comm
/
cvt100.zip
/
VTTIO.C
< prev
Wrap
Text File
|
1988-08-03
|
18KB
|
653 lines
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define NORMAL 0x7 /* Normal video attribute */
#define BOLD 0x8 /* Bold video attribute */
#define UNDERLINED 0xA /* Underlined video attribute */
#define REVERSE 0x70 /* Reverse video attribute */
/****************************************************************************/
/* Function prototypes */
void VTInit( void );
void ConOut( unsigned char );
static void atnrm( unsigned char );
static void (*ttstate)() = atnrm;
static void atescf( unsigned char );
static void AnsiParse( unsigned char );
static void ExtParse( unsigned char );
static void AnsiModeSet( char, int );
static void ExtModeSet( char, int );
static void SetChar0( unsigned char );
static void SetChar1( unsigned char );
static void SetDouble( unsigned char );
static void TransmitId( void );
static void VTBell( void );
/****************************************************************************/
/* Global variables */
unsigned originmode; /* Origin mode, relative or absolute */
unsigned insertmode; /* Insert mode, off or on */
unsigned autowrap; /* Automatic wrap mode, off or on */
unsigned newline; /* Newline mode, off or on, GLOBAL data!*/
unsigned cursorvisible; /* Cursor visibility, on or hidden */
unsigned reversebackground; /* Reverse background attribute, on or off*/
unsigned screenwid; /* Screen column width */
unsigned char log; /* Flag to indicate char logging is on */
/****************************************************************************/
/* External variables */
/****************************************************************************/
/* Local static data */
char term_id_str[]= "[?1;2c"; /* VT100 id string */
#define lansarg 10 /* Max number of ANSI arguments */
static int nansarg = 0; /* Index for ANSI argument list */
static int ansargs[lansarg]; /* Room for 10 ANSI arguments */
static unsigned char lastc; /* Saved last character */
/*****************************************************************************/
/*****************************************************************************/
/* V T I N I T -- */
void VTinit() {
if (GetVTSetup() == 0) { /* If there are no saved values for */
screenwid = 80; /* VT emulation parameters then provid'em */
newline = 0;
autowrap = 0;
insertmode = 0;
cursorvisible = 1;
reversebackground = 0;
log = 0;
}
Setvattr( NORMAL );
ttstate = atnrm; /* initial output state is normal */
SetScroll(0,0);
ClearScreen();
SetCharSet(0, 'B');
SetCharSet(1, 'B');
MapCharSet(0);
ClearAllTabs();
InitTabs();
SetScreenWidth(screenwid);
SetCursorVisibility(cursorvisible);
SetBackGround(reversebackground);
SetCurs(1,1);
SaveCursor();
lastc = '\0';
}
/* C O N O U T -- Put a character to the terminal screen */
void ConOut(unsigned char c) {
(*ttstate) (c);
if (log)
writelog(c);
lastc = c;
}
/* A T N R M -- local routine to process an arbitrary character */
static void atnrm(c) unsigned char c; {
if ( c >= 32 && c < 0x80 )
chrwrite(c);
else switch (c) {
case 27: /* Escape */
ttstate = atescf; /* next state parser is esc follower */
break;
case '\r': /* Carriage return */
SetCurs(1,0);
break;
case '\n': /* Line feed */
if (newline)
SetCurs(1,0);
case 11: /* Vertical tab */
case 12: /* Form feed */
ScrollUp();
break;
case '\a': /* Ring terminal bell */
VTBell();
break;
case 8: /* back space */
SetRelCurs( -1, 0 );
break;
case '\t': /* Horizontal tab */
DoTab();
break;
case 14: /* Map G1 to current */
MapCharSet(1);
break;
case 15: /* Map G0 to current */
MapCharSet(0);
break;
case 5: /* transmit answer back */
break;
default:
}
}
/* A T E S C F -- escape sequence follower */
static void atescf(c) unsigned char c; {
register char *termid = term_id_str;
switch (c) {
case '[': /* Parse ansi args */
memset(ansargs,0,sizeof(ansargs));
nansarg = 0;
ttstate = AnsiParse;
break;
case 'D': /* Index */
ScrollUp();
ttstate = atnrm;
break;
case 'E': /* Carriage return/line feed combination */
SetCurs(1,0);
ScrollUp();
ttstate = atnrm;
break;
case 'M': /* Reverse Index */
ScrollDown();
ttstate = atnrm;
break;
case 'H': /* Set a tab stop */
SetTabStop();
ttstate = atnrm;
break;
case '7': /* Save cursor description */
SaveCursor();
ttstate = atnrm;
break;
case '8': /* Restore cursor description */
RestoreCursor();
ttstate = atnrm;
break;
case '=': /* Enable application keypad */
SetKeyPad(1);
ttstate = atnrm;
break;
case '>': /* Enable numeric keypad */
SetKeyPad(0);
ttstate = atnrm;
break;
case 'c': /* Reset terminal to power on values */
VTInit();
ttstate = atnrm;
break;
case '(': /* Select character set G0 */
ttstate = SetChar0;
break;
case ')': /* Select character set G1 */
ttstate = SetChar1;
break;
case '#': /* Set double high/wide characters */
ttstate = SetDouble;
break;
case 24:
case 26: /* Cancel escape sequence */
ttstate = atnrm;
break;
case 'Z': /* Transmit the terminal ID */
TransmitId();
ttstate = atnrm;
break;
case '\\':
ttstate = atnrm;
break;
case '<':
ttstate = atnrm;
break;
case 'P':
ttstate = atnrm;
break;
case '*':
ttstate = atnrm;
break;
default: /* unrecognized so ignore */
ttstate = atnrm;
break;
}
}
/* A N S I P A R S E -- parse ansi arguments */
static void AnsiParse(c) unsigned char c; {
register int i;
register int j;
c &= 0x7F;
switch(c) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
ansargs[nansarg] = (ansargs[nansarg] * 10) + ( c - '0');
break;
case ';': /* Argument separator */
if ( ++nansarg > lansarg)
ttstate = atnrm;
break;
case 'h': /* Set ANSI mode */
f